package org.codetranslators.compiler.abstractassembly;

import org.codetranslators.common.Label;
import org.codetranslators.common.Temp;

public class AssemTemp extends AssemExp
{
	private Temp temp;
	
	public AssemTemp(Temp temp)
	{
		this.temp = temp;
	}
	
	public Temp getTemp()
	{
		return temp;
	}
	
	public int getType()
	{
		return AssemType.INT_TYPE;
	}
	
	public AssemType translateToCJump(Label testLabel, Label endLabel)
	{
		// Create a constant 0
		AssemConst assemConst0 = new AssemConst(0);
		
		// Create a conditional based on whether this temporary is 1 or 0
		return new AssemCJump(AssemCJump.GT, this, assemConst0,
				testLabel, endLabel);
	}
	
	public AssemType translateToIntType()
	{
		return this;
	}
	
	public String getDescription()
	{
		if(temp == null) return "Temp ??";
		return "Temp (" + temp.toString() + ")";
	}
	
	public AssemExpList children() 
	{
		return null;
	}
	
	public AssemExp build(AssemExpList list)
	{
		return this;
	}
	
	public AssemSeqExp canonize()
	{
		return new AssemSeqExp(null, this);
	}
	
	public int getExpType()
	{
		return AssemExp.TEMP;
	}
	
}
